package Common

import (
	"github.com/gin-gonic/gin"
	"github.com/gookit/goutil/dump"
)

/**
 * Created by Goland
 * User: wkk alisleepy@hotmail.com
 * Time: 2022/4/19 - 00:22
 * Desc: <文件下载>
 */

func DownLoad(c *gin.Context) {
	filePath := c.Query("file_path")
	fileName := c.Query("file_name")
	if len(fileName) == 0 {
		dump.P("下载文件失败，文件名为空")
		return
	}
	if len(filePath) == 0 {
		dump.P("下载文件失败，文件路径为空")
		return
	}

	c.Header("Content-Type", "application/octet-stream")
	//强制浏览器下载
	c.Header("Content-Disposition", "attachment; filename="+fileName)
	//浏览器下载或预览
	c.Header("Content-Disposition", "inline;filename="+fileName)
	c.Header("Content-Transfer-Encoding", "binary")
	c.Header("Cache-Control", "no-cache")
	c.File(filePath)
	return
}
